package com.easy.service.impl;

import com.easy.bean.Cases;
import com.easy.bean.DepIdCount;
import com.easy.dao.IBedDao;
import com.easy.dao.ICasesDao;
import com.easy.service.ICasesService;
import com.easy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CasesServiceImpl implements ICasesService {

    @Autowired
    ICasesDao dao;
    @Autowired
    IBedDao bedD;

    @Override
    public List<Cases> getCases(Cases cases) {

        return dao.getCases(cases);
    }

    @Override
    @Transactional
    public int addCases(Cases cases) {
        //将床位状态改为已使用
        bedD.updateBed(cases.getBid());
        return dao.addCases(cases);
    }

    @Override
    @Transactional
    public int editCasesPay(Cases cases) {
        System.out.println(cases);
        bedD.updateBedStatus(cases.getBid());
        return dao.editCasesPay(cases);


    }

    @Override
    public int delCases(int id) {
        return 0;
    }
    @Override
    public Cases getCasesById(int id){
        return dao.getCasesById(id);
    }

    @Override
    public int editCases(Cases cases) throws Exception{

        int count=dao.editCases(cases);
        if(count==0){
            throw new Exception("修改失败");

        }else {
            return count;
        }


    }



    @Override
    public List<Cases> getCases(Cases cases, Page page) {
        return dao.getCases(cases,page);
    }

    @Override
    public int getCount(Cases cases) {
        return dao.getCount(cases);
    }

    @Override
    public List<DepIdCount> getDep_idCount() {
        for(DepIdCount o: dao.getDep_idCount() ){
            System.out.println(o);
        }
        return dao.getDep_idCount();
    }


}
